#include <iostream>  
#include <vector>  
#include <string>  
#include <cctype> // for isspace  
  
// Helper function to split a string by a delimiter  
std::vector<std::string> splitString(const std::string& str, char delimiter) {  
    std::vector<std::string> tokens;  
    std::string token;  
    for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {  
        if (*it == delimiter) {  
            if (!token.empty()) {  
                tokens.push_back(token);  
                token.clear();  
            }  
        } else {  
            token += *it;  
        }  
    }  
    // Add the last token if any  
    if (!token.empty()) {  
        tokens.push_back(token);  
    }  
    return tokens;  
}  
  
// Split by any whitespace character (space, tab, newline, etc.)  
std::vector<std::string> splitStringByWhitespace(const std::string& str) {  
    std::vector<std::string> tokens;  
    std::string token;  
    bool inToken = false;  
    for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {  
        if (std::isspace(*it)) {  
            if (inToken) {  
                tokens.push_back(token);  
                token.clear();  
                inToken = false;  
            }  
        } else {  
            if (!inToken) {  
                inToken = true;  
            }  
            token += *it;  
        }  
    }  
    // Add the last token if any  
    if (inToken) {  
        tokens.push_back(token);  
    }  
    return tokens;  
}  
  
// SplitStringTest class  
class SplitStringTest {  
public:  
    // Test splitting a string by a normal delimiter (e.g., ',')  
    static void testSplitNormal() {  
        std::string str = "1,2,3,4";  
        char delimiter = ',';  
        std::vector<std::string> result = splitString(str, delimiter);  
  
        std::cout << "Normal Split:" << std::endl;  
        for (std::size_t i = 0; i < result.size(); ++i) {  
            std::cout << result[i] << std::endl;  
        }  
    }  
  
    // Test splitting a string by whitespace (spaces, tabs, newlines)  
    static void testSplitBlank() {  
        std::string str = "1 2\t3\n4";  
        std::vector<std::string> result = splitStringByWhitespace(str);  
  
        std::cout << "Blank Split:" << std::endl;  
        for (std::size_t i = 0; i < result.size(); ++i) {  
            std::cout << result[i] << std::endl;  
        }  
    }  
};  
  
// Entry point for testing  
int main() {  
    SplitStringTest::testSplitNormal();  
    SplitStringTest::testSplitBlank();  
    return 0;  
}
